package gui;

import io.Carpeta;
import java.awt.Color;
import java.util.List;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import logica.Verificador;
import logica.VerificadorException;

/**
 *
 * @author Mariano Zapata
 */
public class PanelExpediente extends javax.swing.JPanel implements DocumentListener, InterfazPestania {

    private RenderPestania renderPestania;
    private Carpeta expediente;
    private boolean modificado;
    private PanelPestaniasControlador ppc;

    /** Creates new form PanelExpediente */
    public PanelExpediente(Carpeta expediente, RenderPestania rp, PanelPestaniasControlador ppc) {
        initComponents();
        this.expediente= expediente;
        this.renderPestania= rp;
        this.ppc= ppc;
        modificado= true; //Para que el evento seleccionoEstado no se ejecute al cargar los datos.
        this.renderPestania.setTitulo(this.expediente.toString());
        this.cargarDatos();
        modificado= false; //El panel queda en un estado correcto.
        this.initListeners();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        caratula = new javax.swing.JTextField();
        tipo = new javax.swing.JTextField();
        iniciado = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        estado = new javax.swing.JComboBox();
        terminado = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        juzgado = new javax.swing.JTextField();
        secretaria = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        juez = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        secretario = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        instancia1 = new javax.swing.JTextField();
        instancia2 = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        instancia3 = new javax.swing.JTextField();
        instancia4 = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        seguimiento = new javax.swing.JTextArea();

        setMinimumSize(new java.awt.Dimension(848, 494));

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Información particular:"));

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel1.setText("Carátula:");

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel2.setText("Tipo:");

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel3.setText("Iniciado:");

        caratula.setToolTipText("Formato: sólo letras (obligatorio).");

        tipo.setToolTipText("Formato: sólo letras (opcional).");

        iniciado.setToolTipText("Formato: dd/mm/aaaa (opcional).");

        jLabel12.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel12.setText("Estado:");

        jLabel13.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel13.setText("Terminado:");

        estado.setMaximumRowCount(5);
        estado.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Iniciado", "Apertura de la prueba", "Alegatos", "Sentencia", "Apelado" }));
        estado.setToolTipText("Seleccione una opción.");
        estado.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                seleccionoEstado(evt);
            }
        });

        terminado.setToolTipText("Formato: dd/mm/aaaa (opcional).");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(caratula, javax.swing.GroupLayout.DEFAULT_SIZE, 702, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(iniciado, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE)
                            .addComponent(tipo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel13, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel12, javax.swing.GroupLayout.DEFAULT_SIZE, 84, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(terminado, javax.swing.GroupLayout.DEFAULT_SIZE, 319, Short.MAX_VALUE)
                            .addComponent(estado, 0, 319, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(caratula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(tipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12)
                    .addComponent(estado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(iniciado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13)
                    .addComponent(terminado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Ubicación:"));

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel4.setText("Juzgado:");

        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel5.setText("Secretaria:");

        juzgado.setToolTipText("Formato: sólo letras (obligatorio).");

        secretaria.setToolTipText("Formato: sólo letras (obligatorio).");

        jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel10.setText("Juez:");

        juez.setToolTipText("Formato: sólo letras (opcional).");

        jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel11.setText("Secretario:");

        secretario.setToolTipText("Formato: sólo letras (opcional).");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(secretaria, javax.swing.GroupLayout.DEFAULT_SIZE, 281, Short.MAX_VALUE)
                    .addComponent(juzgado, javax.swing.GroupLayout.DEFAULT_SIZE, 281, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, 84, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(secretario, javax.swing.GroupLayout.DEFAULT_SIZE, 316, Short.MAX_VALUE)
                    .addComponent(juez, javax.swing.GroupLayout.DEFAULT_SIZE, 316, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(juzgado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10)
                    .addComponent(juez, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(secretaria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11)
                    .addComponent(secretario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Número:"));

        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel6.setText("Primera instancia:");

        jLabel7.setText("Segunda instancia:");

        instancia1.setToolTipText("Formato: letras y números (opcional).");

        instancia2.setToolTipText("Formato: letras y números (opcional).");

        jLabel8.setText("Tercera instancia:");

        jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel9.setText("Cuarta instancia:");

        instancia3.setToolTipText("Formato: letras y números (opcional).");

        instancia4.setToolTipText("Formato: letras y números (opcional).");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(instancia2, javax.swing.GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE)
                    .addComponent(instancia1, javax.swing.GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(instancia4, javax.swing.GroupLayout.DEFAULT_SIZE, 316, Short.MAX_VALUE)
                    .addComponent(instancia3, javax.swing.GroupLayout.DEFAULT_SIZE, 316, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(instancia1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8)
                    .addComponent(instancia3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(instancia2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9)
                    .addComponent(instancia4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Seguimiento:"));

        seguimiento.setColumns(20);
        seguimiento.setFont(new java.awt.Font("Monospaced", 0, 12));
        seguimiento.setLineWrap(true);
        seguimiento.setRows(5);
        seguimiento.setWrapStyleWord(true);
        jScrollPane1.setViewportView(seguimiento);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 796, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void seleccionoEstado(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_seleccionoEstado
        if (!modificado)
        {
            renderPestania.modificado(true);
            modificado= true;
        }
    }//GEN-LAST:event_seleccionoEstado

    @Override
    public String toString() {
        return expediente.toString();
    }

    @Override
    public void insertUpdate(DocumentEvent e) {
        if (!modificado)
        {
            renderPestania.modificado(true);
            modificado= true;
        }
    }

    @Override
    public void removeUpdate(DocumentEvent e) {
        if (!modificado)
        {
            renderPestania.modificado(true);
            modificado= true;
        }
    }

    @Override
    public void changedUpdate(DocumentEvent e) {
        if (!modificado)
        {
            renderPestania.modificado(true);
            modificado= true;
        }
    }

    @Override
    public void cerrar() {
        ppc.cerrarPestania(this);
    }

    public Carpeta getExpediente() {
        return expediente;
    }

    public Carpeta validar() throws VerificadorException
    {
        try {
            this.desmarcarErrores();
            this.trim();
            Verificador.verificarCarpeta(caratula.getText(), juzgado.getText(), secretaria.getText(), iniciado.getText(),
                    terminado.getText());
            expediente.setNombre(caratula.getText());
            expediente.getExpediente().setInstancia1(instancia1.getText());
            expediente.getExpediente().setInstancia2(instancia2.getText());
            expediente.getExpediente().setInstancia3(instancia3.getText());
            expediente.getExpediente().setInstancia4(instancia4.getText());
            expediente.getExpediente().setJuzgado(juzgado.getText());
            expediente.getExpediente().setSecretaria(secretaria.getText());
            expediente.getExpediente().setIniciado(iniciado.getText());
            expediente.getExpediente().setTerminado(terminado.getText());
            expediente.getExpediente().setTipo(tipo.getText());
            expediente.getExpediente().setJuez(juez.getText());
            expediente.getExpediente().setSecretario(secretario.getText());
            expediente.getExpediente().setSeguimiento(seguimiento.getText());
            Integer i= new Integer(estado.getSelectedIndex());
            expediente.getExpediente().setEstado(i.byteValue());
            return expediente;
        } catch (VerificadorException ex) {this.marcarErrores(ex.obtenerErrores());
                                           throw ex;}
    }

    public void setGuardado()
    {
        if (modificado)
        {
            renderPestania.setTitulo(expediente.toString());
            renderPestania.modificado(false);
            modificado= false;
        }
    }

    public boolean estaModificado() {
        return modificado;
    }

    private void cargarDatos()
    {
        caratula.setText(expediente.getNombre());
        tipo.setText(expediente.getExpediente().getTipo());
        Byte b= new Byte(expediente.getExpediente().getEstado());
        estado.setSelectedIndex(b.intValue());
        iniciado.setText(expediente.getExpediente().getIniciado());
        terminado.setText(expediente.getExpediente().getTerminado());
        juzgado.setText(expediente.getExpediente().getJuzgado());
        juez.setText(expediente.getExpediente().getJuez());
        secretaria.setText(expediente.getExpediente().getSecretaria());
        secretario.setText(expediente.getExpediente().getSecretario());
        instancia1.setText(expediente.getExpediente().getInstancia1());
        instancia2.setText(expediente.getExpediente().getInstancia2());
        instancia3.setText(expediente.getExpediente().getInstancia3());
        instancia4.setText(expediente.getExpediente().getInstancia4());
        seguimiento.setText(expediente.getExpediente().getSeguimiento());
    }

    private void initListeners()
    {
        caratula.getDocument().addDocumentListener(this);
        tipo.getDocument().addDocumentListener(this);
        iniciado.getDocument().addDocumentListener(this);
        terminado.getDocument().addDocumentListener(this);
        juzgado.getDocument().addDocumentListener(this);
        juez.getDocument().addDocumentListener(this);
        secretaria.getDocument().addDocumentListener(this);
        secretario.getDocument().addDocumentListener(this);
        instancia1.getDocument().addDocumentListener(this);
        instancia2.getDocument().addDocumentListener(this);
        instancia3.getDocument().addDocumentListener(this);
        instancia4.getDocument().addDocumentListener(this);
        seguimiento.getDocument().addDocumentListener(this);
    }

    private void desmarcarErrores()
    {
        caratula.setBackground(Color.white);
        juzgado.setBackground(Color.white);
        secretaria.setBackground(Color.white);
        iniciado.setBackground(Color.white);
        terminado.setBackground(Color.white);
    }

    private void marcarErrores(List<Integer> errores)
    {
        for (Integer i : errores)
        {
            switch(i)
            {
                case Verificador.ERROR_CARPETA_NOMBRE: caratula.setBackground(Color.red); break;
                case Verificador.ERROR_EXPEDIENTE_JUZGADO: juzgado.setBackground(Color.red); break;
                case Verificador.ERROR_EXPEDIENTE_SECRETARIA: secretaria.setBackground(Color.red); break;
                case Verificador.ERROR_EXPEDIENTE_INICIADO: iniciado.setBackground(Color.red); break;
                case Verificador.ERROR_EXPEDIENTE_TERMINADO: terminado.setBackground(Color.red); break;
            }
        }
    }

    private void trim()
    {
        caratula.setText(caratula.getText().trim());
        tipo.setText(tipo.getText().trim());
        iniciado.setText(iniciado.getText().trim());
        terminado.setText(terminado.getText().trim());
        juzgado.setText(juzgado.getText().trim());
        juez.setText(juez.getText().trim());
        secretaria.setText(secretaria.getText().trim());
        secretario.setText(secretario.getText().trim());
        instancia1.setText(instancia1.getText().trim());
        instancia2.setText(instancia2.getText().trim());
        instancia3.setText(instancia3.getText().trim());
        instancia4.setText(instancia4.getText().trim());
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField caratula;
    private javax.swing.JComboBox estado;
    private javax.swing.JTextField iniciado;
    private javax.swing.JTextField instancia1;
    private javax.swing.JTextField instancia2;
    private javax.swing.JTextField instancia3;
    private javax.swing.JTextField instancia4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField juez;
    private javax.swing.JTextField juzgado;
    private javax.swing.JTextField secretaria;
    private javax.swing.JTextField secretario;
    private javax.swing.JTextArea seguimiento;
    private javax.swing.JTextField terminado;
    private javax.swing.JTextField tipo;
    // End of variables declaration//GEN-END:variables
}
